package com.vtquang.mymaps;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Serializer {
	 public static byte[] serialize(Object obj) throws IOException { 
	        ObjectOutputStream os = null;

	        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000);
	        os = new ObjectOutputStream(new BufferedOutputStream(byteStream));
	        os.flush();
	        os.writeObject(obj);
	        os.flush();
	        byte[] sendBuf = byteStream.toByteArray();
	        os.close();
	        return sendBuf; 
	    }

	    public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
	        ByteArrayInputStream b = new ByteArrayInputStream(bytes);
	        ObjectInputStream o = new ObjectInputStream(b);
	        return o.readObject();
	    }
}
